<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <title>密码修改</title>
    <link rel="stylesheet" href="assets/layui/css/layui.css" th:href="@{/assets/layui/css/layui.css}"  media="all">
    <style>
        html,body{
            margin: 0;
            padding: 0;
            width:100%;
            height: 100%;
            /*color:rgb(0,228,253);*/
            color:#00E4FD;
        }
    </style>
</head>
<body>
<form class="layui-form" action="" lay-filter="dataForm">
    <div class="layui-form-item" th:if="${type} == 'new'" id="trpromt">
        <h3 class="layui-bg-orange">由于您是首次登陆,请修改密码后再登录.</h3>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户账号：</label>
        <div class="layui-input-block">
            <input type="text" id="ipt_userId" th:value="${uid}" name="userId"  readonly  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="c-red">*</span>
            旧密码：</label>
        <div class="layui-input-block">
            <input type="password" placeholder="修改前密码"  lay-verify="required" name="oldPassword" id="oldPassword"   class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="c-red">*</span>
            新密码：</label>
        <div class="layui-input-block">
            <input type="password" placeholder="新密码" lay-verify="required|pwd"  name="newPassword" id="newPassword"    class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="c-red">*</span>
            密码确认：</label>
        <div class="layui-input-block">
            <input type="password" placeholder="确认新密码" lay-verify="required|pwd|pwdconfirm"   name="confirmPassword" id="confirmPassword"    class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block" style="text-align: center;">
            <button class="layui-btn" lay-submit="" lay-filter="formSubmit">提交</button>
        </div>
    </div>
</form>
<script src="assets/layui/layui.js" th:src="@{/assets/layui/layui.js}"></script>
</body>
</html>
<script type="text/javascript">
    layui.config({
        base: 'js/'
    })
    layui.use(['jquery','form','validate','common'], function () {
        var form = layui.form,
            $ = layui.jquery,
            layer = layui.layer,
            validate = layui.validate,
            common = layui.common;
        validate.regVerify();//注册验证
        form.verify({
            pwdconfirm:function (value) {
                var pwd1 = $("#newPassword").val();
                if(pwd1!=value){
                    return "2次输入的密码不一致，请重新输入";
                }
            }
        });

        //监听提交
        form.on('submit(formSubmit)', function (data) {
            //common.consoleDebug(JSON.stringify(data.field));
            $.ajax({
                type: 'POST',
                url: 'sys/user/modifyPassword',
                data: data.field,
                success: function(rtn){

                    // var rtnInfo = $.parseJSON(data);
                    if (rtn.code==0) {
                        common.showInfo('修改成功,请重新登录!',function(){
                            //刷新首页
                            parent.document.location.href = "login";
                        });
                    }
                    else{
                        common.showError(rtn.msg);
                    }
                },
                error: function(XmlHttpRequest, textStatus, errorThrown){
                    common.showError('保存错误');
                }
            });
            return false;
        });
    })
</script>